#Replication file for Appendix of "Defending the Dog Whistle#
#This file contains the code necessary to replicate the analyses and results from
#the online appendix; a separate replication file does the same for the main text.

####Libraries and color palette####
library(ggplot2)
library(interflex)
library(estimatr)
library(cowplot)
#Set color palette
cbbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")

####Table A.1, results behind main text figure 2####
##Load in the 2019 data##
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment")
load("Study 1.RData")

temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_evalR", D = "Implicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_evalR", D = "Explicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c("Indirect", "Indirect", "Indirect",
           "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))

t1

####Table A.2, results for Figure 5####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

#Make the table:
temp=whites[!is.na(whites$implicit_vs_denial),]
m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp$mayor_ft_72=temp$mayor_ft_7/100
m2<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))

t1

####Table A.3, results behind Figure 6####
temp=whites[!is.na(whites$implicit_vs_embrace),]
m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c( "Approval", "Approval", "Approval",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))

t1

###Insensitivity graph for Online Appendix, FIGURE A.2####
#Load in the 2019 data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

t3=t.test(d$mayor_evalR[d$treatment==2|d$treatment==3]~d$treatment[d$treatment==2|d$treatment==3],
          data=d[d$treatment==2|d$treatment==3,])
t4=t.test(d$mayor_insensitiveR[d$treatment==2|d$treatment==3]~d$treatment[d$treatment==2|d$treatment==3],
          data=d[d$treatment==2|d$treatment==3,])

t5=t.test(d$mayor_evalR[d$treatment==4|d$treatment==5]~d$treatment[d$treatment==4|d$treatment==5],
          data=d[d$treatment==4|d$treatment==5,])
t6=t.test(d$mayor_insensitiveR[d$treatment==4|d$treatment==5]~d$treatment[d$treatment==4|d$treatment==5],
          data=d[d$treatment==4|d$treatment==5,])

t <- data.frame(treatment=c("Indirect", "Direct",
                            "Indirect", "Direct"),
                var=c("Mayor's proposal","Mayor's proposal",
                      "Mayor's insensitivity","Mayor's insensitivity"),
                dif=c(t3$estimate[2]-t3$estimate[1],
                      t5$estimate[2]-t5$estimate[1],
                      t4$estimate[2]-t4$estimate[1],
                      t6$estimate[2]-t6$estimate[1]
                ), 
                se=c(
                  t3$stderr,
                  t5$stderr,
                  t4$stderr,
                  t6$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Indirect", "Direct"))
t$var=factor(t$var, levels=c("Mayor's proposal", "Mayor's insensitivity"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.10, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denials", 
       x="",
       caption = "       Graph presents treatment effects for the indirect and direct racial messages, along 
       with 95 percent confidence intervals. The dependent variables are support for the 
       Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 
       1 (most support), and perceptions that the Mayor's plan is racially insensitive, which is 
       a 5 point likert item scaled from 0 (not insensitive at all) to 1 (very insensitive). 
       N is 618 and 600 for the indirect and direct conditions (respectively)")

p=plot1+facet_wrap(vars(var))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("Basic treatment effects, 2019")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.2, study 1, insensitivity and approval.jpeg", width=5, height=6, units="in", dpi=600)

###Insensitivity graph for Online Appendix, FIGURE A.3####
###
temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_insensitiveR", D = "Implicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_insensitiveR", D = "Explicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c("Indirect", "Indirect", "Indirect",
           "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))

#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.20, 0.20))+
  scale_y_continuous(breaks=c(-0.15,-0.075,0,0.075, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="", 
       caption="       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent confidence intervals. The dependent 
       variable is perceptions that the Mayor's plan is racially insensitive, which is a 5 point likert item scaled from 0 (not insensitive at all) to 
       1 (very insensitive). N is those low in racial resentment is 201 and 193 for the indirect and direct conditions (respectively). For those with 
       medium levels of racial resentment, N is 207 (indirect) and 209 (direct); N for those high in racial resentment is 202 (indirect) and 188 (direct).")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+ theme(panel.spacing=unit(.05, "lines"),
                                                                                  panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                  strip.background = element_rect(color = "black", size = 1))+
  ggtitle("Insensitivity of mayor's proposal")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.3, Study 1 insensitivity.jpeg", width=8, height=6, units="in", dpi=600)


####FIGURE A.4, Study 2, insensitivity results####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")
t1=t.test(as.numeric(mayor_eval) ~ as.numeric(implicit_vs_denial), data = whites)
# MAYOR INSENSITIVE
t2=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_denial), data = whites)
# MAYOR VOTE
t3=t.test(as.numeric(mayor_vote) ~ as.numeric(implicit_vs_denial), data = whites)
# MAYOR FT
t4=t.test(as.numeric(mayor_ft_72) ~ as.numeric(implicit_vs_denial), data = whites)

## EMBRACE
t5=t.test(as.numeric(mayor_eval) ~ as.numeric(implicit_vs_embrace), data = whites)
# MAYOR INSENSITIVE
t6=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_embrace), data = whites)
# MAYOR VOTE
t7=t.test(as.numeric(mayor_vote) ~ as.numeric(implicit_vs_embrace), data = whites)
# MAYOR FT
t8=t.test(as.numeric(mayor_ft_72) ~ as.numeric(implicit_vs_embrace), data = whites)

#Embrace vs. denial
t.test(as.numeric(mayor_eval) ~ as.numeric(denial_vs_embrace), data = whites)
# MAYOR INSENSITIVE
t6=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_embrace), data = whites)
# MAYOR VOTE
t.test(as.numeric(mayor_vote) ~ as.numeric(denial_vs_embrace), data = whites)
# MAYOR FT
t.test(as.numeric(mayor_ft_72) ~ as.numeric(denial_vs_embrace), data = whites)

t <- data.frame(treatment=c("Denial", "Denial", "Denial", "Denial",
                            "Appropriation", "Appropriation", "Appropriation", "Appropriation"),
                var=c("Mayor's proposal", "Mayor's insensitivity", "Vote", "FT",
                      "Mayor's proposal","Mayor's insensitivity","Vote", "FT"),
                dif=c(t1$estimate[2]-t1$estimate[1],
                      t2$estimate[2]-t2$estimate[1],
                      t3$estimate[2]-t3$estimate[1],
                      t4$estimate[2]-t4$estimate[1],
                      t5$estimate[2]-t5$estimate[1],
                      t6$estimate[2]-t6$estimate[1],
                      t7$estimate[2]-t7$estimate[1],
                      t8$estimate[2]-t8$estimate[1]
                ), 
                se=c(
                  t1$stderr,
                  t2$stderr,
                  t3$stderr,
                  t4$stderr,
                  t5$stderr,
                  t6$stderr,
                  t7$stderr,
                  t8$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Denial", "Appropriation"))
t$var=factor(t$var, levels=c("Mayor's proposal", "Mayor's insensitivity",
                             "Vote", "FT"))

plot1=ggplot(data = t[t$var=="Mayor's proposal"|t$var=="Mayor's insensitivity",], aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.10, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect over indirect message", 
       x="",
       caption = "       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent 
       confidence intervals. The dependent variables are support for the Mayor's proposed policy, which is a 
       7 point likert item scaled from 0 (least support) to 1 (most support), and perceptions that the Mayor's 
       plan is racially insensitive, which is a 5 point likert item scaled from 0 (not insensitive at all) to 
       1 (very insensitive). N is 553 and 561 for the denial and appropriation conditions (respectively)")

p=plot1+facet_wrap(vars(var))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("Basic treatment effects, 2020")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.4, Study 2 insensitivity.jpeg", width=6, height=6, units="in", dpi=600)

####FIGURE A.5, Study 2, appropriation results broken out by RR####
temp=whites[!is.na(whites$implicit_vs_embrace),]
m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_embrace", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial appropriation", 
       x="",
       caption="       Graph presents treatment effects for appropriations over indirect messages, along with 95 percent confidence intervals. The dependent variables are support for the 
       Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 1 (most support), likelihood of vote for the Mayor, which is a 5 point likert item 
       scaled from 0 (very unlikely) to 1 (very likely), feeling thermometer ratings of the Mayor, which are scaled from 0 (most negative) to 1 (most positive), and perceptions 
       that the Mayor's plan is racially insensitive, which is a 5 point likert item scaled from 0 (not insensitive at all) to 1 (very insensitive).N is those low in racial 
       resentment is 401. For those with medium levels of racial resentment, N is 328; N for those high in racial resentment is 384.")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p

setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.5, Study 2, appropration by RR.jpeg", width=10, height=6, units="in", dpi=600)


####Figure A. 6, denial results broken out by RR####
temp=whites[!is.na(whites$implicit_vs_denial),]

m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_denial", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial denial", 
       x="",
       caption="       Graph presents treatment effects for denials over indirect messages, along with 95 percent confidence intervals. The dependent variables are support for the 
       Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 1 (most support), likelihood of vote for the Mayor, which is a 5 point likert item 
       scaled from 0 (very unlikely) to 1 (very likely), feeling thermometer ratings of the Mayor, which are scaled from 0 (most negative) to 1 (most positive), and perceptions 
       that the Mayor's plan is racially insensitive, which is a 5 point likert item scaled from 0 (not insensitive at all) to 1 (very insensitive). N is those low in racial 
       resentment is 374. For those  with medium levels of racial resentment, N is 345; N for those high in racial resentment is 388.")
)
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.6, Study 2, denial by RR.jpeg", width=10, height=6, units="in", dpi=600)

####Figure A.7, study 1 manipulation check####
#Load in the 2019 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

Diff=c(mean(d$mayor_insensitiveR[d$treatment==0], na.rm=T),
       mean(d$mayor_insensitiveR[d$treatment==1], na.rm=T),
       mean(d$mayor_insensitiveR[d$treatment==2], na.rm=T),
       mean(d$mayor_insensitiveR[d$treatment==3], na.rm=T),
       mean(d$mayor_insensitiveR[d$treatment==4], na.rm=T),
       mean(d$mayor_insensitiveR[d$treatment==5], na.rm=T)
)

se=c(sd(d$mayor_insensitiveR[d$treatment==0], na.rm=T)/sqrt(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==0]))[1])),
     sd(d$mayor_insensitiveR[d$treatment==1], na.rm=T)/sqrt(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==1]))[1])),
     sd(d$mayor_insensitiveR[d$treatment==2], na.rm=T)/sqrt(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==2]))[1])),
     sd(d$mayor_insensitiveR[d$treatment==3], na.rm=T)/sqrt(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==3]))[1])),
     sd(d$mayor_insensitiveR[d$treatment==4], na.rm=T)/sqrt(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==4]))[1])),
     sd(d$mayor_insensitiveR[d$treatment==5], na.rm=T)/sqrt(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==5]))[1]))
)

treat=c("Control",
        "Control + Denial",
        "Indirect",
        "Indirect + Denial",
        "Direct",
        "Direct + Denial"
)

t1=data.frame(cbind(Diff, treat))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$treat=factor(t1$treat, levels=c(
  "Control",
  "Control + Denial",
  "Indirect",
  "Indirect + Denial",
  "Direct",
  "Direct + Denial"
))

(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==0]))[1]))
(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==1]))[1]))
(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==2]))[1]))
(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==3]))[1]))
(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==4]))[1]))
(as.numeric(table(is.na(d$mayor_insensitiveR[d$treatment==5]))[1]))

plot3=ggplot(data = t1, aes(x=treat, y=Diff, fill=treat))+
  geom_col() +
  geom_linerange(aes(ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se))))+
  scale_fill_grey()+
  theme_classic()+
  scale_y_continuous(limits=c(0, 0.7))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="none")+
  theme(legend.title = element_blank())+
  theme(plot.caption = element_text(hjust = 0))+
  labs(title="Perceptions of insenstivity", y= "1=most insenstivie", x="",
       caption="Differences between the conditions without the denials are significant at the p=0.05 level. \nThe same is true of differences between the denial conditions. Differences between the \nconditions and their denial versions are only significant for the control. The dependent \nvariable is perceptions that the Mayor's plan is racially insensitive, which is a 5 point likert \nitem scaled from 0 (not insensitive at all) to 1 (very insensitive). N for the various \nconditions (in order) is 293, 302, 292, 308, 299, and 284")
plot3
t.test(mayor_insensitiveR~treatment, data=d[d$treatment==0|d$treatment==1,])
#Significant
t.test(mayor_insensitiveR~treatment, data=d[d$treatment==2|d$treatment==3,])
#p=0.14
t.test(mayor_insensitiveR~treatment, data=d[d$treatment==4|d$treatment==5,])
#p=0.26
t.test(mayor_insensitiveR~treatment, data=d[d$treatment==0|d$treatment==2,])
t.test(mayor_insensitiveR~treatment, data=d[d$treatment==0|d$treatment==4,])

t.test(mayor_insensitiveR~treatment, data=d[d$treatment==1|d$treatment==3,])
t.test(mayor_insensitiveR~treatment, data=d[d$treatment==1|d$treatment==5,])

setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
jpeg("Figure A.7, Study 1 Manipulation Check by Treatment.jpeg", width=6, height=6, units="in", res=600)
plot3
dev.off()

####Figure A.8, Study 2 manipulation check####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

Diff=c(mean(whites$mayor_insensitive[whites$treatment==0], na.rm=T),
       mean(whites$mayor_insensitive[whites$treatment==1], na.rm=T),
       mean(whites$mayor_insensitive[whites$treatment==2], na.rm=T)
)

se=c(sd(whites$mayor_insensitive[whites$treatment==0], na.rm=T)/sqrt(as.numeric(table(is.na(whites$mayor_insensitive[whites$treatment==0]))[1])),
     sd(whites$mayor_insensitive[whites$treatment==1], na.rm=T)/sqrt(as.numeric(table(is.na(whites$mayor_insensitive[whites$treatment==1]))[1])),
     sd(whites$mayor_insensitive[whites$treatment==2], na.rm=T)/sqrt(as.numeric(table(is.na(whites$mayor_insensitive[whites$treatment==2]))[1]))
)

treat=c("Indirect",
        "Indirect + Denial",
        "Indirect + Appropriation"
)

t1=data.frame(cbind(Diff, treat))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$treat=factor(t1$treat, levels=c(
  "Indirect",
  "Indirect + Denial",
  "Indirect + Appropriation"
))

(as.numeric(table(is.na(whites$mayor_insensitive[whites$treatment==0]))[1]))
(as.numeric(table(is.na(whites$mayor_insensitive[whites$treatment==1]))[1]))
(as.numeric(table(is.na(whites$mayor_insensitive[whites$treatment==2]))[1]))


plot3=ggplot(data = t1, aes(x=treat, y=Diff, fill=treat))+
  geom_col() +
  geom_linerange(aes(ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se))))+
  scale_fill_grey()+
  theme_classic()+
  scale_y_continuous(limits=c(0, 0.7))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="none")+
  theme(legend.title = element_blank())+
  theme(plot.caption = element_text(hjust = 0))+
  labs(title="Perceptions of insenstivity", y= "1=most insenstivie", x="",
       caption="Differences between the indirect and both justifications conditions are significant at the p=0.05 level. \nThe two justifications are not statistically different from one another. The dependent variable is \nperceptions that the Mayor's plan is racially insensitive, which is a 5 point likert item scaled from 0 \n(not insensitive at all) to 1 (very insensitive). N for the conditions (in order) is 541, 551, and 560.")
plot3
t.test(mayor_insensitive~treatment, data=whites[whites$treatment==0|whites$treatment==1,])
#Significant
t.test(mayor_insensitive~treatment, data=whites[whites$treatment==0|whites$treatment==2,])
#p=0.14
t.test(mayor_insensitive~treatment, data=whites[whites$treatment==1|whites$treatment==2,])

setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
jpeg("Figure A.8, Study 2 Manipulation Check by Treatment.jpeg", width=6, height=6, units="in", res=600)
plot3
dev.off()

####FIGURE A.9, regressions####
#Load in the 2019 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

m3=lm_robust(mayor_evalR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==0,])
m3.2=lm_robust(mayor_evalR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==1,])
m3.3=lm_robust(mayor_evalR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==2,])
m3.4=lm_robust(mayor_evalR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==3,])
m3.5=lm_robust(mayor_evalR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==4,])
m3.6=lm_robust(mayor_evalR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==5,])

m4=lm_robust(mayor_insensitiveR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==0,])
m4.2=lm_robust(mayor_insensitiveR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==1,])
m4.3=lm_robust(mayor_insensitiveR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==2,])
m4.4=lm_robust(mayor_insensitiveR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==3,])
m4.5=lm_robust(mayor_insensitiveR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==4,])
m4.6=lm_robust(mayor_insensitiveR~rr_scale+age+as.factor(gender)+HHI+pidR+ideoR+media_attention, data=d[d$treatment==5,])


#Time to graph
Diff=c(m3$coefficients[2],
       m3.2$coefficients[2],
       m3.3$coefficients[2],
       m3.4$coefficients[2],
       m3.5$coefficients[2],
       m3.6$coefficients[2],
       m4$coefficients[2],
       m4.2$coefficients[2],
       m4.3$coefficients[2],
       m4.4$coefficients[2],
       m4.5$coefficients[2],
       m4.6$coefficients[2]
)

se=c(
  m3$std.error[2],
  m3.2$std.error[2], 
  m3.3$std.error[2], 
  m3.4$std.error[2], 
  m3.5$std.error[2], 
  m3.6$std.error[2], 
  m4$std.error[2],
  m4.2$std.error[2], 
  m4.3$std.error[2], 
  m4.4$std.error[2], 
  m4.5$std.error[2], 
  m4.6$std.error[2]
)

Var=c("Mayor's proposal", 
      "Mayor's proposal", 
      "Mayor's proposal", 
      "Mayor's proposal", 
      "Mayor's proposal", 
      "Mayor's proposal", 
      "Mayor's insensitivity",
      "Mayor's insensitivity",
      "Mayor's insensitivity",
      "Mayor's insensitivity",
      "Mayor's insensitivity",
      "Mayor's insensitivity"
)
t1=data.frame(cbind(Diff, Var))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)
t1$Var=factor(Var, levels=c(
  "Mayor's proposal", "Mayor's insensitivity" 
))

t1$Group=c(
  "Control", "Control+denial", "Indirect", "Indirect+denial", "Direct", "Direct+denial",
  "Control", "Control+denial", "Indirect", "Indirect+denial", "Direct", "Direct+denial"
  
)
t1$Group=factor(t1$Group, levels=c(
  "Control", "Control+denial", "Indirect", "Indirect+denial", "Direct", "Direct+denial"
))

#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  coord_cartesian(ylim = c(-0.09, 0.08))+
  scale_y_continuous(breaks=c(-0.08,-0.04,0,0.04, 0.08))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="Control condition", 
       y= "Coefficient", 
       x="")
p=plot1+facet_wrap(vars(Var))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.9, Study 1 Regression approach.jpeg", width=11, height=8, units="in", dpi=600)

####Table A.4####
#Load in the 2019 data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")
#Control group compared to indirect condition:
t.test(d$mayor_evalR[d$treatment==0], d$mayor_evalR[d$treatment==2] )
#Control group compared to indirect + denial condition:
t.test(d$mayor_evalR[d$treatment==0], d$mayor_evalR[d$treatment==3] )
#Control group compared to direct condition:
t.test(d$mayor_evalR[d$treatment==0], d$mayor_evalR[d$treatment==4] )
#Control group compared to direct + denial condition:
t.test(d$mayor_evalR[d$treatment==0], d$mayor_evalR[d$treatment==5] )

####Figure A.12####
#load in 2019 data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")
temp=d[!is.na(d$Control_reject),]
m0<-interflex("binning", Y = "mayor_evalR", D = "Control_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_evalR", D = "Implicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_evalR", D = "Explicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c( "Control", "Control", "Control",
            "Indirect", "Indirect", "Indirect",
            "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Control", "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.15, 0.15))+
  scale_y_continuous(breaks=c(-0.15,-0.075,0,0.075, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="",
       caption = "       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent confidence intervals. The dependent 
       variable is support for the Mayor's proposed policy, which is a 7 point Likert item scaled from 0 (least support) to 1 (most support). N for those 
       low in racial resentment is 193 (control), 201 (indirect) and 193 (direct). For those with medium levels of racial resentment, N is 184 (control),
       207 (indirect), and 209 (direct); N for those high in racial resentment is 213 (control), 202 (indirect), and 188 (direct).")

p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("Approval of mayor's proposal")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.12, Study 1 Approval of proposal with controls.jpeg", width=8, height=6, units="in", dpi=600)

####Figure A.13####
#load in 2019 data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")
temp=d[!is.na(d$Control_reject),]
m0<-interflex("binning", Y = "mayor_insensitiveR", D = "Control_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_insensitiveR", D = "Implicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_insensitiveR", D = "Explicit_reject", X = "rr_scale", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c( "Control", "Control", "Control",
            "Indirect", "Indirect", "Indirect",
            "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Control", "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.2, 0.2))+
  scale_y_continuous(breaks=c(-0.1,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="",
       caption = "       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent confidence intervals. The dependent 
       variable is perceptions that the Mayor's plan is racially insensitive, which is a 5 point likert item scaled from 0 (not insensitive at all) to 1 
       (very insensitive). N for those low in racial resentment is 193 (control), 201 (indirect) and 193 (direct). For those with medium levels of racial 
       resentment, N is 184 (control), 207 (indirect), and 209 (direct); N for those high in racial resentment is 213 (control), 202 (indirect), and 
       188 (direct).")

p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("Insensitivity of mayor's proposal")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.13, Study 1 Insensitivity of proposal with controls.jpeg", width=8, height=6, units="in", dpi=600)

####Table A.5####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")
#Gender
prop.table(table(whites$gender))

#Party; 
#Republicans
prop.table(table(whites$pid))[5]+prop.table(table(whites$pid))[6]+prop.table(table(whites$pid))[7]
#Independents
prop.table(table(whites$pid))[4]
#Democrats
prop.table(table(whites$pid))[1]+prop.table(table(whites$pid))[2]+prop.table(table(whites$pid))[3]

#Income
median(whites$hhi[whites$hhi>=0], na.rm=T)
#This value corresponds to the range of $50,000-54,999

#Age
mean(whites$age, na.rm=T)

#Days watching the news
#This variable needs to be corrected; it skips the value of 7 and starts at 1.
whites$media2=whites$media
whites$media2[whites$media==8]=7
whites$media2[whites$media==9]=8
whites$media2=whites$media2-1
table(whites$media, whites$media2)
mean(whites$media2, na.rm=T)

#Discussing politics
#This variable needs to be corrected; it skips the value of 7 and starts at 1.
whites$talk_politics2=whites$talk_politics
whites$talk_politics2[whites$talk_politics==8]=7
whites$talk_politics2[whites$talk_politics==9]=8
whites$talk_politics2=whites$talk_politics2-1
table(whites$talk_politics, whites$talk_politics2)
mean(whites$talk_politics2, na.rm=T)

#Racial resentment
mean(whites$rr_scale, na.rm=T)

####Table A.6####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")
#Gender
prop.table(table(nonwhites$gender))

#Party; 
#Republicans
prop.table(table(nonwhites$pid))[5]+prop.table(table(nonwhites$pid))[6]+prop.table(table(nonwhites$pid))[7]
#Independents
prop.table(table(nonwhites$pid))[4]
#Democrats
prop.table(table(nonwhites$pid))[1]+prop.table(table(nonwhites$pid))[2]+prop.table(table(nonwhites$pid))[3]

#Income
median(nonwhites$hhi[nonwhites$hhi>=0], na.rm=T)
#This value corresponds to the range of $30,000-34,999

#Age
mean(nonwhites$age, na.rm=T)

#Days watching the news
#This variable needs to be corrected; it skips the value of 7 and starts at 1.
nonwhites$media2=nonwhites$media
nonwhites$media2[nonwhites$media==8]=7
nonwhites$media2[nonwhites$media==9]=8
nonwhites$media2=nonwhites$media2-1
table(nonwhites$media, nonwhites$media2)
mean(nonwhites$media2, na.rm=T)

#Discussing politics
#This variable needs to be corrected; it skips the value of 7 and starts at 1.
nonwhites$talk_politics2=nonwhites$talk_politics
nonwhites$talk_politics2[nonwhites$talk_politics==8]=7
nonwhites$talk_politics2[nonwhites$talk_politics==9]=8
nonwhites$talk_politics2=nonwhites$talk_politics2-1
table(nonwhites$talk_politics, nonwhites$talk_politics2)
mean(nonwhites$talk_politics2, na.rm=T)

#Racial resentment
mean(nonwhites$rr_scale, na.rm=T)

####Figure A.14, people of color and approval####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

t1=t.test(as.numeric(mayor_eval) ~ as.numeric(implicit_vs_denial), data = whites)
t2=t.test(as.numeric(mayor_eval) ~ as.numeric(implicit_vs_denial), data = blacks)
t3=t.test(as.numeric(mayor_eval) ~ as.numeric(implicit_vs_denial), data = hispanics)
t4=t.test(as.numeric(mayor_eval) ~ as.numeric(implicit_vs_denial), data = other)

t <- data.frame(treatment=c("Whites", "Blacks", "Hispanics", "Other"),
                dif=c(t1$estimate[2]-t1$estimate[1],
                      t2$estimate[2]-t2$estimate[1],
                      t3$estimate[2]-t3$estimate[1],
                      t4$estimate[2]-t4$estimate[1]
                ), 
                se=c(
                  t1$stderr,
                  t2$stderr,
                  t3$stderr,
                  t4$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Whites","Blacks", "Hispanics", "Other"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.10, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="Approval of policy", 
       y= "Effect of denial over indirect message", 
       x="",
       caption="       Graph presents treatment effects for the denial over the indirect racial messages, along 
       with 95 percent confidence intervals. The dependent variable is support for the 
       Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 
       1 (most support). N is 1097 (Whites), 243 (Blacks), 246 (Hispanics), and 294 (Other).")
plot1
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.14 - Study 2, Approval all racial groups.jpeg", width=6, height=6, units="in", dpi=600)

nrow(whites[!is.na(whites$mayor_eval)&!is.na(whites$implicit_vs_denial),])
nrow(blacks[!is.na(blacks$mayor_eval),])
nrow(hispanics[!is.na(hispanics$mayor_eval),])
nrow(other[!is.na(other$mayor_eval),])

####Figure A.15, people of color and sensitivity####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

t1=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_denial), data = whites)
t2=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_denial), data = blacks)
t3=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_denial), data = hispanics)
t4=t.test(as.numeric(mayor_insensitive) ~ as.numeric(implicit_vs_denial), data = other)

t <- data.frame(treatment=c("Whites", "Blacks", "Hispanics", "Other"),
                dif=c(t1$estimate[2]-t1$estimate[1],
                      t2$estimate[2]-t2$estimate[1],
                      t3$estimate[2]-t3$estimate[1],
                      t4$estimate[2]-t4$estimate[1]
                ), 
                se=c(
                  t1$stderr,
                  t2$stderr,
                  t3$stderr,
                  t4$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Whites","Blacks", "Hispanics", "Other"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.20, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="Insensitivity of policy", 
       y= "Effect of denial over indirect message", 
       x="",
       caption="       Graph presents treatment effects for the denial over the indirect racial messages, along 
       with 95 percent confidence intervals. The dependent variable is sperceptions that the Mayor's 
       plan is racially insensitive, which is a 5 point likert item scaled from 0 (not insensitive 
       at all) to 1 (very insensitive). N is 1092 (Whites), 245 (Blacks), 242 (Hispanics), and 289 (Other).")
plot1
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.15 - Study 2, Insensitivity all racial groups.jpeg", width=6, height=6, units="in", dpi=600)

nrow(whites[!is.na(whites$mayor_insensitive)&!is.na(whites$implicit_vs_denial),])
nrow(blacks[!is.na(blacks$mayor_insensitive),])
nrow(hispanics[!is.na(hispanics$mayor_insensitive),])
nrow(other[!is.na(other$mayor_insensitive),])

####Figure A.16 people of color and vote####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

t1=t.test(as.numeric(mayor_vote) ~ as.numeric(implicit_vs_denial), data = whites)
t2=t.test(as.numeric(mayor_vote) ~ as.numeric(implicit_vs_denial), data = blacks)
t3=t.test(as.numeric(mayor_vote) ~ as.numeric(implicit_vs_denial), data = hispanics)
t4=t.test(as.numeric(mayor_vote) ~ as.numeric(implicit_vs_denial), data = other)

t <- data.frame(treatment=c("Whites", "Blacks", "Hispanics", "Other"),
                dif=c(t1$estimate[2]-t1$estimate[1],
                      t2$estimate[2]-t2$estimate[1],
                      t3$estimate[2]-t3$estimate[1],
                      t4$estimate[2]-t4$estimate[1]
                ), 
                se=c(
                  t1$stderr,
                  t2$stderr,
                  t3$stderr,
                  t4$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Whites","Blacks", "Hispanics", "Other"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.20, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="Vote for Mayor", 
       y= "Effect of denial over indirect message", 
       x="",
       caption="       Graph presents treatment effects for the denial over the indirect racial messages, along 
       with 95 percent confidence intervals. The dependent variable is likelihood of vote for the Mayor, which 
       is a 5 point likert item scaled from 0 (very unlikely) to 1 (very likely). N is 1094 (Whites), 243 (Blacks), 
       244 (Hispanics), and 292 (Other).")
plot1
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.16 - Study 2, Vote all racial groups.jpeg", width=6, height=6, units="in", dpi=600)

nrow(whites[!is.na(whites$mayor_vote)&!is.na(whites$implicit_vs_denial),])
nrow(blacks[!is.na(blacks$mayor_vote),])
nrow(hispanics[!is.na(hispanics$mayor_vote),])
nrow(other[!is.na(other$mayor_vote),])

####Figure A.17 people of color and FT####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

whites$mayor_ft_72=whites$mayor_ft_7/100
blacks$mayor_ft_72=blacks$mayor_ft_7/100
hispanics$mayor_ft_72=hispanics$mayor_ft_7/100
other$mayor_ft_72=other$mayor_ft_7/100

t1=t.test(as.numeric(mayor_ft_72) ~ as.numeric(implicit_vs_denial), data = whites)
t2=t.test(as.numeric(mayor_ft_72) ~ as.numeric(implicit_vs_denial), data = blacks)
t3=t.test(as.numeric(mayor_ft_72) ~ as.numeric(implicit_vs_denial), data = hispanics)
t4=t.test(as.numeric(mayor_ft_72) ~ as.numeric(implicit_vs_denial), data = other)

t <- data.frame(treatment=c("Whites", "Blacks", "Hispanics", "Other"),
                dif=c(t1$estimate[2]-t1$estimate[1],
                      t2$estimate[2]-t2$estimate[1],
                      t3$estimate[2]-t3$estimate[1],
                      t4$estimate[2]-t4$estimate[1]
                ), 
                se=c(
                  t1$stderr,
                  t2$stderr,
                  t3$stderr,
                  t4$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Whites","Blacks", "Hispanics", "Other"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.20, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="FT of the Mayor", 
       y= "Effect of denial over indirect message", 
       x="",
       caption="       Graph presents treatment effects for the denial over the indirect racial messages, along 
       with 95 percent confidence intervals. The dependent variable is feeling thermometer ratings of the Mayor, 
       which are scaled from 0 (most negative) to 1 (most positive). N is 1094 (Whites), 243 (Blacks), 
       244 (Hispanics), and 292 (Other).")
plot1
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.17 - Study 2, FT all racial groups.jpeg", width=6, height=6, units="in", dpi=600)

nrow(whites[!is.na(whites$mayor_ft_72)&!is.na(whites$implicit_vs_denial),])
nrow(blacks[!is.na(blacks$mayor_ft_72),])
nrow(hispanics[!is.na(hispanics$mayor_ft_72),])
nrow(other[!is.na(other$mayor_ft_72),])

####Table A.7####
#Load in the 2019 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")
##Study 1
#Gender
prop.table(table(d$gender))
#Party; 
#Republicans
prop.table(table(d$pid))[5]+prop.table(table(d$pid))[6]+prop.table(table(d$pid))[7]
#Independents
prop.table(table(d$pid))[4]
#Democrats
prop.table(table(d$pid))[1]+prop.table(table(d$pid))[2]+prop.table(table(d$pid))[3]

#Income
median(d$HHI[d$HHI>=0], na.rm=T)
#This value corresponds to the range of $40,000-44,999

#Age
mean(d$age, na.rm=T)

#Racial resentment
mean(d$rr_scale, na.rm=T)

##Study 2
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")
#Gender
prop.table(table(whites$gender))

#Party; 
#Republicans
prop.table(table(whites$pid))[5]+prop.table(table(whites$pid))[6]+prop.table(table(whites$pid))[7]
#Independents
prop.table(table(whites$pid))[4]
#Democrats
prop.table(table(whites$pid))[1]+prop.table(table(whites$pid))[2]+prop.table(table(whites$pid))[3]

#Income
median(whites$hhi[whites$hhi>=0], na.rm=T)
#This value corresponds to the range of $50,000-54,999

#Age
mean(whites$age, na.rm=T)

#Racial resentment
mean(whites$rr_scale, na.rm=T)

####Figure A.18, Perceptions of party and Ideology Study 1####
#Load in the 2019 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")
t3=t.test(d$mayor_viewsR[d$treatment==2|d$treatment==3]~d$treatment[d$treatment==2|d$treatment==3],
          data=d[d$treatment==2|d$treatment==3,])
t4=t.test(d$mayor_pidR[d$treatment==2|d$treatment==3]~d$treatment[d$treatment==2|d$treatment==3],
          data=d[d$treatment==2|d$treatment==3,])
#Explicit vs. Explicit + denial
t5=t.test(d$mayor_viewsR[d$treatment==4|d$treatment==5]~d$treatment[d$treatment==4|d$treatment==5],
          data=d[d$treatment==4|d$treatment==5,])
t6=t.test(d$mayor_pidR[d$treatment==4|d$treatment==5]~d$treatment[d$treatment==4|d$treatment==5],
          data=d[d$treatment==4|d$treatment==5,])


#With Control
t7=t.test(d$mayor_viewsR[d$treatment==0|d$treatment==1]~d$treatment[d$treatment==0|d$treatment==1],
          data=d[d$treatment==0|d$treatment==1,])
t8=t.test(d$mayor_pidR[d$treatment==0|d$treatment==1]~d$treatment[d$treatment==0|d$treatment==1],
          data=d[d$treatment==0|d$treatment==1,])

t <- data.frame(treatment=c("Indirect", "Direct", "Control",
                            "Indirect", "Direct", "Control"),
                var=c("Mayor's ideology","Mayor's ideology","Mayor's ideology",
                      "Mayor's party","Mayor's party","Mayor's party"),
                dif=c(t3$estimate[2]-t3$estimate[1],
                      t5$estimate[2]-t5$estimate[1],
                      t7$estimate[2]-t7$estimate[1],
                      t4$estimate[2]-t4$estimate[1],
                      t6$estimate[2]-t6$estimate[1],
                      t8$estimate[2]-t8$estimate[1]
                ), 
                se=c(
                  t3$stderr,
                  t5$stderr,
                  t7$stderr,
                  t4$stderr,
                  t6$stderr,
                  t8$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Indirect", "Direct", "Control"))
t$var=factor(t$var, levels=c("Mayor's ideology", "Mayor's party"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.15, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denials", 
       x="",
       caption="       Graph presents treatment effects for the denial over the different messages, along with 95 percent confidence intervals. 
       The dependent variable are placement of the mayor on a 7 point scale from strong liberal (0) to strong conservative (1) 
       and party as a binary variable, where 1 is guessing the mayor is a Republican and 0 is guessing Democrat or neither party. 
       N is 612 (control), 618 (indirect), and 600 (direct).")
p=plot1+facet_wrap(vars(var))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("Ideology and Party results, 2019")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.18, Study 1 - Ideology and Party with control.jpeg", width=8, height=6, units="in", dpi=600)

nrow(d[d$treatment<2,])
nrow(d[d$treatment==2|d$treatment==3,])
nrow(d[d$treatment==4|d$treatment==5,])

####Figure A.19####
#Party
Diff=c(as.numeric(prop.table(table(d$Mayor_Party[d$treatment==0]))[3]),
       as.numeric(prop.table(table(d$Mayor_Party[d$treatment==1]))[3]),
       as.numeric(prop.table(table(d$Mayor_Party[d$treatment==2]))[3]),
       as.numeric(prop.table(table(d$Mayor_Party[d$treatment==3]))[3]),
       as.numeric(prop.table(table(d$Mayor_Party[d$treatment==4]))[3]),
       as.numeric(prop.table(table(d$Mayor_Party[d$treatment==5]))[3])
)

se=c(sqrt((Diff[1]*(1-Diff[1]))/(as.numeric(table(is.na(d$Mayor_Party[d$treatment==0]))[1]))),
     sqrt((Diff[2]*(1-Diff[2]))/(as.numeric(table(is.na(d$Mayor_Party[d$treatment==1]))[1]))),
     sqrt((Diff[3]*(1-Diff[3]))/(as.numeric(table(is.na(d$Mayor_Party[d$treatment==2]))[1]))),
     sqrt((Diff[4]*(1-Diff[4]))/(as.numeric(table(is.na(d$Mayor_Party[d$treatment==3]))[1]))),
     sqrt((Diff[5]*(1-Diff[5]))/(as.numeric(table(is.na(d$Mayor_Party[d$treatment==4]))[1]))),
     sqrt((Diff[6]*(1-Diff[6]))/(as.numeric(table(is.na(d$Mayor_Party[d$treatment==5]))[1])))
)

treat=c("Control",
        "Control + Denial",
        "Indirect",
        "Indirect + Denial",
        "Direct",
        "Direct + Denial"
)

t1=data.frame(cbind(Diff, treat))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$treat=factor(t1$treat, levels=c(
  "Control",
  "Control + Denial",
  "Indirect",
  "Indirect + Denial",
  "Direct",
  "Direct + Denial"
))

plot1=ggplot(data = t1, aes(x=treat, y=Diff, fill=treat))+
  geom_col() +
  geom_linerange(aes(ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se))))+
  scale_fill_grey()+
  theme_classic()+
  scale_y_continuous(limits=c(0, 0.6))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="none")+
  theme(legend.title = element_blank())+
  theme(plot.caption = element_text(hjust = 0))+
  labs(title="Partisanship of Mayor", y= "Proportion guessing Republican", x="")
plot1

table(d$Mayor_Party[d$treatment==4])[3]
table(d$Mayor_Party[d$treatment==4])
prop.test(x=c(table(d$Mayor_Party[d$treatment==4])[3],table(d$Mayor_Party[d$treatment==5])[3]), 
          n=c(table(is.na(d$Mayor_Party[d$treatment==4]))[1],table(is.na(d$Mayor_Party[d$treatment==5]))[1]))
#p=0.14
prop.test(x=c(table(d$Mayor_Party[d$treatment==0])[3],table(d$Mayor_Party[d$treatment==1])[3]), 
          n=c(table(is.na(d$Mayor_Party[d$treatment==0]))[1],table(is.na(d$Mayor_Party[d$treatment==1]))[1]))
#p=0.11

#Now for ideology; let's make it similar - the proportion of people who guess conservative
Diff=c(as.numeric(prop.table(table(d$mayor_views3[d$treatment==0]))[3]),
       as.numeric(prop.table(table(d$mayor_views3[d$treatment==1]))[3]),
       as.numeric(prop.table(table(d$mayor_views3[d$treatment==2]))[3]),
       as.numeric(prop.table(table(d$mayor_views3[d$treatment==3]))[3]),
       as.numeric(prop.table(table(d$mayor_views3[d$treatment==4]))[3]),
       as.numeric(prop.table(table(d$mayor_views3[d$treatment==5]))[3])
)

se=c(sqrt((Diff[1]*(1-Diff[1]))/(as.numeric(table(is.na(d$mayor_views3[d$treatment==0]))[1]))),
     sqrt((Diff[2]*(1-Diff[2]))/(as.numeric(table(is.na(d$mayor_views3[d$treatment==1]))[1]))),
     sqrt((Diff[3]*(1-Diff[3]))/(as.numeric(table(is.na(d$mayor_views3[d$treatment==2]))[1]))),
     sqrt((Diff[4]*(1-Diff[4]))/(as.numeric(table(is.na(d$mayor_views3[d$treatment==3]))[1]))),
     sqrt((Diff[5]*(1-Diff[5]))/(as.numeric(table(is.na(d$mayor_views3[d$treatment==4]))[1]))),
     sqrt((Diff[6]*(1-Diff[6]))/(as.numeric(table(is.na(d$mayor_views3[d$treatment==5]))[1])))
)

treat=c("Control",
        "Control + Denial",
        "Indirect",
        "Indirect + Denial",
        "Direct",
        "Direct + Denial"
)

t1=data.frame(cbind(Diff, treat))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$treat=factor(t1$treat, levels=c(
  "Control",
  "Control + Denial",
  "Indirect",
  "Indirect + Denial",
  "Direct",
  "Direct + Denial"
))

plot2=ggplot(data = t1, aes(x=treat, y=Diff, fill=treat))+
  geom_col() +
  geom_linerange(aes(ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se))))+
  scale_fill_grey()+
  theme_classic()+
  scale_y_continuous(limits=c(0, 0.6))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="none")+
  theme(legend.title = element_blank())+
  theme(plot.caption = element_text(hjust = 0))+
  labs(title="Ideology of Mayor", y= "Proportion guessing Conservative", x="",
       caption="       Graphs show the percentage of respondents guessing that the Mayor is a Republican / conservative along with .
       90% confidence intervals. No differences between the conditions and their denial versions are significant at the 
       p=0.05 level. The dependent variables are binary variables where 1 indicates guessing the Mayor is a Republican
       or conservative and 0 is any other guess. Ns are 293, 303, 293, 309, 300, and 284 respectively")
plot2

prop.test(x=c(table(d$mayor_views3[d$treatment==4])[3],table(d$mayor_views3[d$treatment==5])[3]), 
          n=c(table(is.na(d$mayor_views3[d$treatment==4]))[1],table(is.na(d$mayor_views3[d$treatment==5]))[1]))
#p=0.54
prop.test(x=c(table(d$mayor_views3[d$treatment==0])[3],table(d$mayor_views3[d$treatment==1])[3]), 
          n=c(table(is.na(d$mayor_views3[d$treatment==0]))[1],table(is.na(d$mayor_views3[d$treatment==1]))[1]))
#p~1
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
jpeg("Figure A.19, Study 1 Perceptions of party and ideology.jpeg", width=7, height=8, units="in", res=600)
plot_grid(plot1, plot2, nrow=2)
dev.off()

table(d$treatment)

####Figure A.20####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

whites$mayor_pidR[whites$mayor_pid==2]=1
whites$mayor_pidR[whites$mayor_pid==1|whites$mayor_pid==3]=0

#Denial
t3=t.test(whites$mayor_views[whites$treatment==0|whites$treatment==1]~whites$treatment[whites$treatment==0|whites$treatment==1],
          data=whites[whites$treatment==0|whites$treatment==1,])
t4=t.test(whites$mayor_pidR[whites$treatment==0|whites$treatment==1]~whites$treatment[whites$treatment==0|whites$treatment==1],
          data=whites[whites$treatment==0|whites$treatment==1,])
#Appropriation
t5=t.test(whites$mayor_views[whites$treatment==0|whites$treatment==2]~whites$treatment[whites$treatment==0|whites$treatment==2],
          data=whites[whites$treatment==0|whites$treatment==2,])
t6=t.test(whites$mayor_pidR[whites$treatment==0|whites$treatment==2]~whites$treatment[whites$treatment==0|whites$treatment==2],
          data=whites[whites$treatment==0|whites$treatment==2,])


t <- data.frame(treatment=c("Denial", "Appropriation",
                            "Denial", "Appropriation"),
                var=c("Mayor's ideology","Mayor's ideology",
                      "Mayor's party","Mayor's party"),
                dif=c(t3$estimate[2]-t3$estimate[1],
                      t5$estimate[2]-t5$estimate[1],
                      t4$estimate[2]-t4$estimate[1],
                      t6$estimate[2]-t6$estimate[1]
                ), 
                se=c(
                  t3$stderr,
                  t5$stderr,
                  t4$stderr,
                  t6$stderr
                )
)

t$treatment=factor(t$treatment, levels=c("Denial", "Appropriation"))
t$var=factor(t$var, levels=c("Mayor's ideology", "Mayor's party"))

plot1=ggplot(data = t, aes(x=treatment, y=dif, ymin=I(dif-(1.96*se)), ymax=I(dif+(1.96*se)), color=treatment))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=treatment)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.10, 0.10))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of justifications", 
       x="",
       caption="       Graph presents treatment effects for the justifications over the indirect message, along with 95 percent confidence intervals. 
       The dependent variable are placement of the mayor on a 7 point scale from strong liberal (0) to strong conservative (1) 
       and party as a binary variable, where 1 is guessing the mayor is a Republican and 0 is guessing Democrat or neither party. 
       N is 553 (denial), and 561 (appropriation).")
p=plot1+facet_wrap(vars(var))+theme(strip.text.x = element_text(size = 12))+theme(strip.background = element_blank())+
  ggtitle("Ideology and Party results, 2020")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.20, Study 2 - Ideology and Party.jpeg", width=8, height=6, units="in", dpi=600)

table(whites$treatment)

####Figure A.21####
#Load in the 2020 data:
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

Diff=c(as.numeric(prop.table(table(whites$Mayor_Party[whites$treatment==0]))[3]),
       as.numeric(prop.table(table(whites$Mayor_Party[whites$treatment==1]))[3]),
       as.numeric(prop.table(table(whites$Mayor_Party[whites$treatment==2]))[3])
)

se=c(sqrt((Diff[1]*(1-Diff[1]))/(as.numeric(table(is.na(whites$Mayor_Party[whites$treatment==0]))[1]))),
     sqrt((Diff[2]*(1-Diff[2]))/(as.numeric(table(is.na(whites$Mayor_Party[whites$treatment==1]))[1]))),
     sqrt((Diff[3]*(1-Diff[3]))/(as.numeric(table(is.na(whites$Mayor_Party[whites$treatment==2]))[1])))
)

treat=c("Indirect",
        "Indirect + denial",
        "Indirect + appropriation"
)

t1=data.frame(cbind(Diff, treat))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$treat=factor(t1$treat, levels=c(
  "Indirect",
  "Indirect + denial",
  "Indirect + appropriation"
))

plot1=ggplot(data = t1, aes(x=treat, y=Diff, fill=treat))+
  geom_col() +
  geom_linerange(aes(ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se))))+
  scale_fill_grey()+
  theme_classic()+
  scale_y_continuous(limits=c(0, 0.7))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="none")+
  theme(legend.title = element_blank())+
  theme(plot.caption = element_text(hjust = 0))+
  labs(title="Partisanship of Mayor", y= "Proportion guessing Republican", x="")
plot1

table(whites$Mayor_Party[whites$treatment==4])[3]
table(whites$Mayor_Party[whites$treatment==4])
prop.test(x=c(table(whites$Mayor_Party[whites$treatment==0])[3],table(whites$Mayor_Party[whites$treatment==1])[3]), 
          n=c(table(is.na(whites$Mayor_Party[whites$treatment==0]))[1],table(is.na(whites$Mayor_Party[whites$treatment==1]))[1]))
#p=0.82
prop.test(x=c(table(whites$Mayor_Party[whites$treatment==0])[3],table(whites$Mayor_Party[whites$treatment==2])[3]), 
          n=c(table(is.na(whites$Mayor_Party[whites$treatment==0]))[1],table(is.na(whites$Mayor_Party[whites$treatment==2]))[1]))
#p=0.17

#Now for ideology; let's make it similar - the proportion of people who guess conservative
whites$mayor_views3[whites$mayor_views<0.5]=1
whites$mayor_views3[whites$mayor_views==0.5]=2
whites$mayor_views3[whites$mayor_views>0.5]=3

Diff=c(as.numeric(prop.table(table(whites$mayor_views3[whites$treatment==0]))[3]),
       as.numeric(prop.table(table(whites$mayor_views3[whites$treatment==1]))[3]),
       as.numeric(prop.table(table(whites$mayor_views3[whites$treatment==2]))[3])
)

se=c(sqrt((Diff[1]*(1-Diff[1]))/(as.numeric(table(is.na(whites$mayor_views3[whites$treatment==0]))[1]))),
     sqrt((Diff[2]*(1-Diff[2]))/(as.numeric(table(is.na(whites$mayor_views3[whites$treatment==1]))[1]))),
     sqrt((Diff[3]*(1-Diff[3]))/(as.numeric(table(is.na(whites$mayor_views3[whites$treatment==2]))[1])))
)

treat=c("Indirect",
        "Indirect + denial",
        "Indirect + appropriation"
)

t1=data.frame(cbind(Diff, treat))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$treat=factor(t1$treat, levels=c(
  "Indirect",
  "Indirect + denial",
  "Indirect + appropriation"
))

plot2=ggplot(data = t1, aes(x=treat, y=Diff, fill=treat))+
  geom_col() +
  geom_linerange(aes(ymin=I(Diff-(1.645*se)), ymax=I(Diff+(1.645*se))))+
  scale_fill_grey()+
  theme_classic()+
  scale_y_continuous(limits=c(0, 0.7))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="none")+
  theme(legend.title = element_blank())+
  theme(plot.caption = element_text(hjust = 0))+
  labs(title="Ideology of Mayor", y= "Proportion guessing Conservative", x="",
       caption="       Graphs show the percentage of respondents guessing that the Mayor is a Republican / conservative along 
       with 90% confidence intervals. No differences between the conditions and their denial versions are 
       significant at the p=0.05 level. The dependent variables are binary variables where 1 indicates guessing 
       the Mayor is a Republican or conservative and 0 is any other guess. Ns are 544, 553, and 561 respectively")
plot2

prop.test(x=c(table(whites$mayor_views3[whites$treatment==0])[3],table(whites$mayor_views3[whites$treatment==2])[3]), 
          n=c(table(is.na(whites$mayor_views3[whites$treatment==0]))[1],table(is.na(whites$mayor_views3[whites$treatment==2]))[1]))
#p=0.23
prop.test(x=c(table(whites$mayor_views3[whites$treatment==0])[3],table(whites$mayor_views3[whites$treatment==1])[3]), 
          n=c(table(is.na(whites$mayor_views3[whites$treatment==0]))[1],table(is.na(whites$mayor_views3[whites$treatment==1]))[1]))
#p=0.29

setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
jpeg("Figure A.21, Study 2 Ideology and Party by Treatment.jpeg", width=6.5, height=8, units="in", res=600)
plot_grid(plot1, plot2, nrow=2)
dev.off()

table(whites$treatment)

####Correlation b/w partisanship and racial resentment####
##Study 1
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

cor.test(d$rr_scale[d$pid!=8], d$pid[d$pid!=8])
d$pid3[d$pid<4]=1
d$pid3[d$pid==4|d$pid==8]=2
d$pid3[d$pid>4&d$pid<8]=3
t.test(rr_scale~pid3, data=d[d$pid3!=2,])
quantile(d$rr_scale[d$pid3==1], 0.66, na.rm=T)
quantile(d$rr_scale[d$pid3==3], 0.20, na.rm=T)

##Study 2
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

cor.test(whites$rr_scale[whites$pid!=8], whites$pid[whites$pid!=8])
whites$pid3[whites$pid<4]=1
whites$pid3[whites$pid==4|whites$pid==8]=2
whites$pid3[whites$pid>4&whites$pid<8]=3
t.test(rr_scale~pid3, data=whites[whites$pid3!=2,])
quantile(whites$rr_scale[whites$pid3==1], 0.75, na.rm=T)
quantile(whites$rr_scale[whites$pid3==3], 0.20, na.rm=T)

####Figure A.22####
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

#Recoding to get it started:
d$pid3[d$pid<4]=1
d$pid3[d$pid==4|d$pid==8]=2
d$pid3[d$pid>4&d$pid<8]=3

d$dem=ifelse(d$pid3==1&!is.na(d$pid3), 1, 0)
d$ind=ifelse(d$pid3==2&!is.na(d$pid3), 1, 0)
d$rep=ifelse(d$pid3==3&!is.na(d$pid3), 1, 0)

temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_evalR", D = "Implicit_reject", X = "rr_scale", Z= c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_evalR", D = "Explicit_reject", X = "rr_scale", Z= c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c("Indirect", "Indirect", "Indirect",
           "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))

#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.15, 0.20))+
  scale_y_continuous(breaks=c(-0.15,-0.075,0,0.075, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="",
       caption="       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent confidence intervals. The dependent 
       variable is support for the Mayor's proposed policy, which is a 7 point Likert item scaled from 0 (least support) to 1 (most support). 
       N is those low in racial resentment is 201 and 193 for the indirect and direct conditions (respectively). For those with medium levels 
       of racial resentment, N is 207 (indirect) and 209 (direct); N for those high in racial resentment is 202 (indirect) and 188 (direct).
       This model includes controls for the party of the respondent in the form of binary variables for Democrat, Republican, and Independent.")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+ theme(panel.spacing=unit(.05, "lines"),
                                                                                  panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                  strip.background = element_rect(color = "black", size = 1))+
  ggtitle("Approval of mayor's proposal")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.22, Study 1 Approval of proposal_pid controls.jpeg", width=8, height=6, units="in", dpi=600)

#Alternative with party as continuous
temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_evalR", D = "Implicit_reject", X = "rr_scale", Z= "pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_evalR", D = "Explicit_reject", X = "rr_scale", Z= "pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c("Indirect", "Indirect", "Indirect",
           "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))

#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  coord_cartesian(ylim = c(-0.15, 0.20))+
  scale_y_continuous(breaks=c(-0.15,-0.075,0,0.075, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+ theme(panel.spacing=unit(.05, "lines"),
                                                                                  panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                  strip.background = element_rect(color = "black", size = 1))+
  ggtitle("Approval of mayor's proposal")
p

####FIGURE A.23 ####
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

#Some recoding first
whites$pid3[whites$pid<4]=1
whites$pid3[whites$pid==4|whites$pid==8]=2
whites$pid3[whites$pid>4&whites$pid<8]=3

whites$dem=ifelse(whites$pid3==1&!is.na(whites$pid3), 1, 0)
whites$ind=ifelse(whites$pid3==2&!is.na(whites$pid3), 1, 0)
whites$rep=ifelse(whites$pid3==3&!is.na(whites$pid3), 1, 0)


temp=whites[!is.na(whites$implicit_vs_denial),]

m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_denial", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_denial", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_denial", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")

#### This will need recoding
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_denial", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing

plot1=ggplot(data = t1[t1$Group!="Insens.",], aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
    coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial denial", 
       x="",
       caption="       Graph presents treatment effects for the denial messages over indirect messages, along with 95 percent confidence intervals. The dependent 
       variables are support for the Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 1 (most support), 
       likelihood of vote for the Mayor, which is a 5 point likert item scaled from 0 (very unlikely) to 1 (very likely), and feeling thermometer 
       ratings of the Mayor, which are scaled from 0 (most negative) to 1 (most positive). N is those low in racial resentment is 374. For those
       with medium levels of racial resentment, N is 345; N for those high in racial resentment is 388.")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.23, Study 2 - Denial comparison pid controls.jpeg", width=8, height=6, units="in", dpi=600)

#continuous pid variable
whites$pidR=whites$pid
whites$pidR[whites$pid==8]=4

temp=whites[!is.na(whites$implicit_vs_embrace),]
m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

#### This will need recoding
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing
plot1=ggplot(data = t1[t1$Group!="Insens.",], aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial denial", 
       x="")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p

####Figure A.24####
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

#Some recoding first
whites$pid3[whites$pid<4]=1
whites$pid3[whites$pid==4|whites$pid==8]=2
whites$pid3[whites$pid>4&whites$pid<8]=3

whites$dem=ifelse(whites$pid3==1&!is.na(whites$pid3), 1, 0)
whites$ind=ifelse(whites$pid3==2&!is.na(whites$pid3), 1, 0)
whites$rep=ifelse(whites$pid3==3&!is.na(whites$pid3), 1, 0)


temp=whites[!is.na(whites$implicit_vs_embrace),]

m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_embrace", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_embrace", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_embrace", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")

#### This will need recoding
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_embrace", X = "rr_scale", Z=c("dem", "rep"), data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing

plot1=ggplot(data = t1[t1$Group!="Insens.",], aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial appropriation", 
       x="",
       caption="       Graph presents treatment effects for the appropriation messages over indirect messages, along with 95 percent confidence intervals. The  
       dependent variables are support for the Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 1 (most support), 
       likelihood of vote for the Mayor, which is a 5 point likert item scaled from 0 (very unlikely) to 1 (very likely), and feeling thermometer 
       ratings of the Mayor, which are scaled from 0 (most negative) to 1 (most positive). N is those low in racial resentment is 401. For those  
       with medium levels of racial resentment, N is 328; N for those high in racial resentment is 384.")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.24, Study 2 - Appropriation comparison pid controls.jpeg", width=8, height=6, units="in", dpi=600)

#continuous pid variable
whites$pidR=whites$pid
whites$pidR[whites$pid==8]=4

temp=whites[!is.na(whites$implicit_vs_embrace),]
m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

#### This will need recoding
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_embrace", X = "rr_scale", Z="pidR", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR",
     "Low RR", "Medium RR", "High RR"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low RR", "Medium RR", "High RR"
))


#These commands do the actual graphing
plot1=ggplot(data = t1[t1$Group!="Insens.",], aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial appropriation", 
       x="")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p

####FIGURE A.25####
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_evalR", D = "Implicit_reject", X = "discrim_r2", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_evalR", D = "Explicit_reject", X = "discrim_r2", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low", "Medium", "High",
     "Low", "Medium", "High"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c("Indirect", "Indirect", "Indirect",
           "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low", "Medium", "High"
))

#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.15, 0.25))+
  scale_y_continuous(breaks=c(-0.15,-0.075,0,0.075, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="",
       caption = "       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent confidence intervals. The dependent 
       variable is support for the Mayor's proposed policy, which is a 7 point Likert item scaled from 0 (least support) to 1 (most support). 
       N is those low in racial resentment is 201 and 193 for the indirect and direct conditions (respectively). For those with medium levels 
       of racial resentment, N is 207 (indirect) and 209 (direct); N for those high in racial resentment is 202 (indirect) and 188 (direct).
       Note that higher levels of the discrimination variable indicate respondents think less attention should be paid to discrimination")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+ theme(panel.spacing=unit(.05, "lines"),
                                                                                  panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                  strip.background = element_rect(color = "black", size = 1))+
  ggtitle("Approval of mayor's proposal")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.25, Study 1 Approval of proposal_Discrim_moderator.jpeg", width=8, height=6, units="in", dpi=600)

####Figure A.26####
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Denial experiment/Study 1.RData")

temp=d[!is.na(d$Implicit_reject),]
m1<-interflex("binning", Y = "mayor_evalR", D = "Implicit_reject", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
temp=d[!is.na(d$Explicit_reject),]
m2<-interflex("binning", Y = "mayor_evalR", D = "Explicit_reject", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")


Diff=c(m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2]
)

se=c(m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3]
)

rr=c("Low", "Medium", "High",
     "Low", "Medium", "High"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)

t1$Group=c("Indirect", "Indirect", "Indirect",
           "Direct", "Direct", "Direct"
)
t1$Group=factor(t1$Group, levels=c(
  "Indirect", "Direct"
))
t1$rr=factor(t1$rr, levels=c(
  "Low", "Medium", "High"
))

#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_text(size=10),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.20, 0.20))+
  scale_y_continuous(breaks=c(-0.15,-0.075,0,0.075, 0.15))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of denial", 
       x="",
       caption = "       Graph presents treatment effects for the indirect and direct racial messages, along with 95 percent confidence intervals. The dependent 
       variable is support for the Mayor's proposed policy, which is a 7 point Likert item scaled from 0 (least support) to 1 (most support). 
       N is those low in racial resentment is 201 and 193 for the indirect and direct conditions (respectively). For those with medium levels 
       of racial resentment, N is 207 (indirect) and 209 (direct); N for those high in racial resentment is 202 (indirect) and 188 (direct).
       Note that lower levels of the feeling thermometer variable indicate colder feelings towards Blacks, relative to Whites")

p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+ theme(panel.spacing=unit(.05, "lines"),
                                                                                  panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                  strip.background = element_rect(color = "black", size = 1))+
  ggtitle("Approval of mayor's proposal")
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.26, Study 1 Approval of proposal_FT_moderator.jpeg", width=8, height=6, units="in", dpi=600)

####FIGURE A.27 APPENDIX####
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

temp=whites[!is.na(whites$implicit_vs_denial),]

m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_denial", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_denial", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_denial", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

#### This will need recoding
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_denial", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low", "Medium", "High",
     "Low", "Medium", "High",
     "Low", "Medium", "High",
     "Low", "Medium", "High"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low", "Medium", "High"
))


#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial denial", 
       x="",
       caption = "       Graph presents treatment effects for the denial messages over indirect messages, along with 95 percent confidence intervals. The dependent 
       variables are support for the Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 1 (most support), 
       likelihood of vote for the Mayor, which is a 5 point likert item scaled from 0 (very unlikely) to 1 (very likely), and feeling thermometer 
       ratings of the Mayor, which are scaled from 0 (most negative) to 1 (most positive). N is those low in racial resentment is 374. For those
       with medium levels of racial resentment, N is 345; N for those high in racial resentment is 388. Note that lower levels of the feeling 
       thermometer variable indicate colder feelings towards Blacks, relative to Whites")
p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.27, Study 2 - Denial comparison FT moderator.jpeg", width=8, height=6, units="in", dpi=600)

#### FIGURE A.28 APPENDIX####
#Load in the data
load("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Data/Lucid Partisanship/Study 2 Data.RData")

temp=whites[!is.na(whites$implicit_vs_embrace),]
m0<-interflex("binning", Y = "mayor_eval", D = "implicit_vs_embrace", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m1<-interflex("binning", Y = "mayor_insensitive", D = "implicit_vs_embrace", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")
m2<-interflex("binning", Y = "mayor_vote", D = "implicit_vs_embrace", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

#### This will need recoding
temp$mayor_ft_72=temp$mayor_ft_7/100
m3<-interflex("binning", Y = "mayor_ft_72", D = "implicit_vs_embrace", X = "ft_race", data = as.data.frame(temp),
              na.rm=T, vartype="simu")

Diff=c(m0$est.bin$`1`[1,2],
       m0$est.bin$`1`[2,2],
       m0$est.bin$`1`[3,2],
       m1$est.bin$`1`[1,2],
       m1$est.bin$`1`[2,2],
       m1$est.bin$`1`[3,2],
       m2$est.bin$`1`[1,2],
       m2$est.bin$`1`[2,2],
       m2$est.bin$`1`[3,2],
       m3$est.bin$`1`[1,2],
       m3$est.bin$`1`[2,2],
       m3$est.bin$`1`[3,2]
)

se=c(m0$est.bin$`1`[1,3],
     m0$est.bin$`1`[2,3],
     m0$est.bin$`1`[3,3],
     m1$est.bin$`1`[1,3],
     m1$est.bin$`1`[2,3],
     m1$est.bin$`1`[3,3],
     m2$est.bin$`1`[1,3],
     m2$est.bin$`1`[2,3],
     m2$est.bin$`1`[3,3],
     m3$est.bin$`1`[1,3],
     m3$est.bin$`1`[2,3],
     m3$est.bin$`1`[3,3]
)


rr=c("Low", "Medium", "High",
     "Low", "Medium", "High",
     "Low", "Medium", "High",
     "Low", "Medium", "High"
)

t1=data.frame(cbind(Diff, rr))
t1$se=as.numeric(se)
t1$Diff=as.numeric(Diff)



t1$Group=c( "Approval", "Approval", "Approval",
            "Insens.", "Insens.", "Insens.",
            "Vote", "Vote", "Vote",
            "FT", "FT", "FT"
)
t1$Group=factor(t1$Group, levels=c("Insens.", "Approval", "Vote", "FT"))

t1$rr=factor(t1$rr, levels=c(
  "Low", "Medium", "High"
))


#These commands do the actual graphing

plot1=ggplot(data = t1, aes(x=Group, y=Diff, ymin=I(Diff-(1.96*se)), ymax=I(Diff+(1.96*se)), color=Group))+
  geom_pointrange(size=1.5, fatten=2, aes(shape=Group)) +
  geom_hline(yintercept=0, size=1, linetype="dashed", color="red") +
  scale_color_manual(values=cbbPalette)+
  theme_classic()+
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(size=14),
        axis.title.y = element_text(size=14),
        plot.title = element_text(size=12))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(legend.position="bottom")+
  theme(legend.key.size = unit(3,"line"))+
  theme(legend.title = element_blank())+
  theme(plot.caption.position = "plot",
        plot.caption = element_text(hjust = 0)) +
  coord_cartesian(ylim = c(-0.3, 0.3))+
  scale_y_continuous(breaks=c(-0.2,-0.1,0,0.1, 0.2))+
  guides(color=guide_legend(keywidth = 2, keyheight = 5))+
  guides(color = guide_legend(nrow = 1))+
  labs(title="", 
       y= "Effect of racial appropriation", 
       x="",
       caption = "       Graph presents treatment effects for appropriations over indirect messages, along with 95 percent confidence intervals. The dependent 
       variables are support for the Mayor's proposed policy, which is a 7 point likert item scaled from 0 (least support) to 1 (most support), 
       likelihood of vote for the Mayor, which is a 5 point likert item scaled from 0 (very unlikely) to 1 (very likely), and feeling thermometer 
       ratings of the Mayor, which are scaled from 0 (most negative) to 1 (most positive). N is those low in racial resentment is 401. For those  
       with medium levels of racial resentment, N is 328; N for those high in racial resentment is 384. Note that lower levels of the feeling 
       thermometer variable indicate colder feelings towards Blacks, relative to Whites")

p=plot1+facet_wrap(vars(rr))+theme(strip.text.x = element_text(size = 12))+theme(panel.spacing=unit(.05, "lines"),
                                                                                 panel.border = element_rect(color = "black", fill = NA, size = 1), 
                                                                                 strip.background = element_rect(color = "black", size = 1))
p
setwd("C:/Users/busby89/Google Drive/Explicit and Implicit messaging/Final POBE graphs")
ggsave("Figure A.28, Study 2 - Appropriation comparison FT moderator.jpeg", width=8, height=6, units="in", dpi=600)